<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Contracts\Validation\Validator;
use Illuminate\Http\Exceptions\HttpResponseException;

class VerifyIndexLogin extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'account'   =>'
               string',
            'password'  =>'required|min:6|max:15'
        ];
    }

    public function messages()
    {
        return [
            'account.string'   =>'请输入字符串',
            'password.required' =>'密码必填',
            'password.min'      =>'至少输入6位字符',
            'password.max'      =>'最对输入15位字符'
        ];
    }

    protected function failedValidation(Validator $validator)
    {
        throw(new HttpResponseException(response()->json(['massages' => $validator->errors()->all(), 'code' => '100'])));
    }
}
